package com.hpf.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpf.lease.common.config.CommonException;
import com.hpf.lease.common.result.ResultCodeEnum;
import com.hpf.lease.model.bean.FeeKey;
import com.hpf.lease.web.admin.vo.FeeInfoVo;
import com.hpf.lease.web.admin.mapper.FeeKeyMapper;
import com.hpf.lease.web.admin.service.FeeKeyService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author GOD
* @description 针对表【fee_key(杂项费用名称表)】的数据库操作Service实现
* @createDate 2024-08-29 15:00:50
*/
@Service
public class FeeKeyServiceImpl extends ServiceImpl<FeeKeyMapper, FeeKey>
    implements FeeKeyService {
    @Resource
    FeeKeyMapper feeKeyMapper;

    @Override
    public boolean saveOrUpdateInfo(FeeKey feeKey) {
        Long id = feeKey.getId() == null ? -1L : feeKey.getId();
        FeeKey one = this.getOne(Wrappers.lambdaQuery(FeeKey.class)
                .eq(FeeKey::getName, feeKey.getName())
                .last("limit 1")
        );
        if (one != null && !feeKey.getId().equals(id)){
            throw new CommonException(ResultCodeEnum.FEE_KEY_EXISTS_ERROR);
        }
        return this.saveOrUpdate(feeKey);
    }

    @Override
    public List<FeeInfoVo> selectAll() {
        return feeKeyMapper.selectAll();
    }
}




